package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JButton;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JComboBox;

public class Визуализатор_для_дерева extends JFrame implements MouseListener{

	private JPanel contentPane;
	
	public static JFrame workFrame;
	final static int minWidth = 450, minHeight = 300;
	
	final Слушатель_Команд listener = new Слушатель_Команд();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					//workFrame = new Визуализатор_для_дерева();
					Визуализатор_для_дерева frame = new Визуализатор_для_дерева();
					frame.setVisible(true);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public static void start() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					//workFrame = new Визуализатор_для_дерева();
					Визуализатор_для_дерева frame = new Визуализатор_для_дерева();
					frame.setVisible(true);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Визуализатор_для_дерева() {
		workFrame = this;
		
		setTitle("Дерево поиска");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setMinimumSize(new Dimension(minWidth, minHeight));
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{0, 300, 0};
		gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0};
		gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 1.0};
		gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 1.0};
		contentPane.setLayout(gbl_contentPane);
		
		
		JPanel panel = new PanelForSearchTree(minWidth, minHeight, workFrame);
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 0);
		gbc_panel.gridwidth = 3;
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 2;
		contentPane.add(panel, gbc_panel);
		
		JComboBox<String> comboBox = new JComboBox<String>();
		comboBox.setModel(new DefaultComboBoxModel<String>(new String[] {"", "8 7 10 9 8",
		"50 51 50 49 52 48 20 21 49"}));
		
		comboBox.setEditable(true);
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.gridwidth = 2;
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 0;
		gbc_comboBox.gridy = 1;
		contentPane.add(comboBox, gbc_comboBox);
		comboBox.setActionCommand(PanelForSearchTree.добавить_элементы);
		comboBox.addActionListener((ActionListener) panel);
		
		//this.getContentPane().addKeyListener((KeyListener) panel);
		//this.addMouseListener((MouseListener) panel);
		/*
		JButton btnNewButton = new JButton("Добавить элементы...");
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton.gridx = 0;
		gbc_btnNewButton.gridy = 0;
		contentPane.add(btnNewButton, gbc_btnNewButton);
		btnNewButton.setActionCommand(PanelForSearchTree.добавить_элементы);
		btnNewButton.addActionListener((ActionListener) panel);
		*/
		
		JButton btnNewButton_1 = new JButton("Найти элемент...");
		GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
		gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_1.gridx = 1;
		gbc_btnNewButton_1.gridy = 0;
		contentPane.add(btnNewButton_1, gbc_btnNewButton_1);
		btnNewButton_1.setActionCommand(PanelForSearchTree.найти_элемент);
		btnNewButton_1.addActionListener((ActionListener) panel);
		btnNewButton_1.setMnemonic(KeyEvent.VK_F);
		
		JButton button = new JButton("Справка");
		GridBagConstraints gbc_button = new GridBagConstraints();
		gbc_button.insets = new Insets(0, 0, 0, 5);
		gbc_button.gridx = 0;
		gbc_button.gridy = 3;
		contentPane.add(button, gbc_button);
		button.setMnemonic(KeyEvent.VK_F1);
		button.setActionCommand(PanelForSearchTree.помощь);
		button.addActionListener((ActionListener) panel);
		
		JButton btnNewButton = new JButton("Очистить всё");
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton.gridx = 0;
		gbc_btnNewButton.gridy = 0;
		contentPane.add(btnNewButton, gbc_btnNewButton);
		btnNewButton.setActionCommand(PanelForSearchTree.очистка);
		btnNewButton.setMnemonic(KeyEvent.VK_F8);
		btnNewButton.addActionListener((ActionListener) panel);
		
		//btnNewButton_1.addKeyListener(btnNewButton_1);
		
	}


	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println("Mouse clicked");
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
